<?php
class PanelAction extends Action{
    
    public function panel(){
    	global $userSession,$cookieTools;
    	
    	$skinUrl = $cookieTools->getCookie("skinUrl");
    	if(isset($skinUrl))
    		$this->smarty->assign("skinUrl",$skinUrl);
    	
    	if (!$userSession->validateLogin()){
    		smartyDisplay($this->smarty,'/manage/page/login/login.html');
    		return $this->SMARTY;
    	}
    	
    	tsLoad('/core/CoreLib/validateLogin.php');
        tsLoad('/manage/busi/SysUserBusi.class.php');
        tsLoad('/manage/busi/IndexsBusi.class.php');
        $sysUserBusi = new SysUserBusi();
        $indexBusi = new IndexsBusi();
        
        //根据用户信息取得用户的菜单权限信息
        $rootMenus = $sysUserBusi->queryUserVisitRootMenus($userSession->getUserSession());
        $userGold = $indexBusi->getUserGold($userSession->getUserSession()["userId"]);
        $roleDescs = $indexBusi->getRoles($userSession->getUserSession()["userId"]);
        $this->smarty->assign("rootMenus",json_encode($rootMenus));
        $this->smarty->assign("userInfo",$userSession->getUserSession());
        $this->smarty->assign("userGold",$userGold);
        $this->smarty->assign("roles",$roleDescs);
        
        smartyDisplay($this->smarty,'/manage/page/panel/panel.html');
        return $this->SMARTY;
    }
    
    //查询用户可以查询的菜单信息
    public function queryUserMenus(){
    	global $userSession,$param;
    	$params = $param->getParams();
    	tsLoad('/manage/busi/SysUserBusi.class.php');
    	$sysUserBusi = new SysUserBusi();
    	
    	$params["userId"] = $userSession->getUserSession()["userId"];
    	//根据用户信息取得用户的菜单权限信息
    	$menus = $sysUserBusi->queryUserVisitAllMenus($params);
    	$this->assign("menus",$menus);
    	
    	return $this->JSON;
    }
    
    //通过菜单ID查询该菜单下的子菜单，查2级
    public function queryUserVisitMenusByParentMenuId(){
    	global $param;
    	global $userSession;
    	$parems = $param->getParams();
    	
    	if($userSession->getUserSession()==null)
    		return false;
    	else 
    		$parems['userId']=$userSession->getUserSession()['userId'];
    	
    	tsLoad('/manage/busi/SysUserBusi.class.php');
    	$sysUserBusi = new SysUserBusi();
    	$menuChildren = $sysUserBusi->queryUserVisitMenusByParentMenuId($parems);
    	 
    	$this->assign("menuChildren",$menuChildren);
    	return $this->JSON;
    }
    //收入明细
    public function queryIncomeInfo(){
    	global $userSession;
    	tsLoad('/manage/busi/IndexsBusi.class.php');
    	$indexBusi = new IndexsBusi();
    	
    	$incomeInfo = $indexBusi->queryIncomeInfos($userSession->getUserSession()["userId"]);
    	
    	$this->assign("rows",$incomeInfo);
    	return $this->JSON;
    }
   
 //赠送野猪币
    public function giveGlod(){
    	tsLoad('/manage/busi/IndexsBusi.class.php');
    	global $param,$userSession;;
    	$params = $param->getParams();
    	$indexBusi = new IndexsBusi();
    	
    	$params['userId']=$userSession->getUserSession()['userId'];
    	$params['userLoginId']=$userSession->getUserSession()['userLoginId'];
    	$result = $indexBusi->giveGlods($params);
    	
    	$this->assign("result",$result);
    	return $this->JSON;
    }
 //得到我的野猪币
    public function queryMyGlod(){
    	global $userSession;
    	tsLoad('/manage/busi/IndexsBusi.class.php');
    	$indexBusi = new IndexsBusi();
    	$result = $indexBusi->getUserGold($userSession->getUserSession()["userId"]);
    
    	$this->assign("result",$result);
    	return $this->JSON;
    }
    //修改密码
    public function updatePwd(){
    	global $param,$userSession;
    	$params = $param->getParams();
    	$params['userId']=$userSession->getUserSession()['userId'];
    	tsLoad('/manage/busi/IndexsBusi.class.php');
    	$indexBusi = new IndexsBusi();
    	
    	$result = $indexBusi->updatemyPwd($params);
    
    	$this->assign("result",$result);
    	return $this->JSON;
    }
}
?>